package com.rmt.www.serviceImpl;

import com.opensymphony.xwork2.ActionContext;
import com.rmt.www.dao.UserDao;
import com.rmt.www.service.LogonService;
import com.rmt.www.vo.User;

public class LogonServiceImpl implements LogonService {

	private UserDao userDao;
	
	public String[] logonResult(String username, String password) {
		User u=userDao.getUser(username);
		if(u==null){
			return new String[]{"noaccount", "this account doesn't exist!"};
		}
		if(!u.getPassword().equals(password)){
			return new String[] {"invalidpassword", "invalid password" };
		}
		//将当前登陆用户信息添加到Session中
		ActionContext.getContext().getSession().put("currentUser", u);
		String type=u.getType();
		//判断用户类型，管理员和非管理员
		if(type.equals("admin")){
			return new String[] {"admin", "hello admin"};
		}else{
			return new String[] {"others", "hello others"};
		}
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public User getUser(String username) {
		return userDao.getUser(username);
	}

}
